-- ============================================
-- Author:		<Le Dang Minh>
-- Create date: <1/22/2010>
-- Description:	<Change user's password store procedure>
-- =============================================
USE TimeSheet
GO
IF EXISTS(SELECT * FROM sys.objects WHERE type = 'P' AND name = 'usp_Change_password')
     DROP PROCEDURE usp_Change_password
GO
CREATE PROCEDURE usp_Change_password
@username NVARCHAR(256),
@oldpass NVARCHAR(512),
@newpass NVARCHAR(512)
AS
  BEGIN
  	/*check user exist*/
  	IF EXISTS(SELECT u.UserId FROM users u WHERE u.Username=@username AND u.[Password]=@oldpass)
  	BEGIN
  		UPDATE users
  	    SET
  		[Password] = @newpass
  	    WHERE
  	    Username=@username
  	    AND [Password]=@oldpass
  	END
  	ELSE
  		RAISERROR ('Username or old password is not exist!!',11,1)
  END
